Skip to content

FIX: expand ~ in profile paths before reading file#39

Open
nattsw wants to merge 2 commits intomainfrom
fix-tilde-profile-path
Open

FIX: expand ~ in profile paths before reading file#39
nattsw wants to merge 2 commits intomainfrom
fix-tilde-profile-path

Conversation

@nattsw
Copy link

@nattsw nattsw commented Jan 28, 2026

When passing --profile ~/.mcps/foo.json, the shell does not expand ~ if the argument is quoted or passed programmatically (e.g. from Claude config). This PR resolves ~ at the start of the path so profile loading works regardless of how the argument arrives.

before fix

➜  discourse-mcp git:(main) pnpm build && node dist/index.js --profile '~/.mcps/d-derp.json'
 
> @discourse/mcp@0.2.4 build /Users/derp/work/discourse/discourse-mcp
> tsc -p tsconfig.json

[2026-01-28T09:33:27.781Z] ERROR Failed to load profile: ENOENT: no such file or directory, open '~/.mcps/d-derp.json'

after fix

➜  discourse-mcp git:(fix-tilde-profile-path) pnpm build && node dist/index.js --profile '~/.mcps/d-derp.json'
 
> @discourse/mcp@0.2.4 build /Users/derp/work/discourse/discourse-mcp
> tsc -p tsconfig.json

[2026-01-28T09:33:51.077Z] INFO Starting Discourse MCP v0.2.4

When passing --profile ~/.mcps/foo.json, the shell does not expand ~
if the argument is quoted or passed programmatically (e.g. from Claude
Code MCP config). Use os.homedir() to resolve ~ at the start of the
path so profile loading works regardless of how the argument arrives.
@SamSaffron
Copy link
Member

Its fine, but maybe get it working for Windows? should we support ~sam?

@xfalcox
Copy link
Member

xfalcox commented Feb 3, 2026

Doesn't the terminal does this automatically? You need to remove the quotes.

node dist/index.js --site https://meta.discourse.org --profile ~/.config/discourse-mcp/meta.json --log_level debug
[2026-02-03T14:24:02.850Z] INFO Starting Discourse MCP v0.2.4
[2026-02-03T14:24:02.859Z] DEBUG Config: {"auth_pairs":[{"site":"https://meta.discourse.org","user_api_key":"123123123","user_api_client_id":"discourse-mcp"}],"read_only":true,"allow_writes":false,"timeout_ms":15000,"concurrency":4,"log_level":"debug","tools_mode":"auto","site":"https://meta.discourse.org","max_read_length":50000,"transport":"stdio","port":3000}
[2026-02-03T14:24:02.859Z] DEBUG HTTP GET https://meta.discourse.org/about.json
[2026-02-03T14:24:03.566Z] DEBUG HTTP GET https://meta.discourse.org/about.json -> 200 OK
[2026-02-03T14:24:03.569Z] INFO Tethered to site: https://meta.discourse.org (Discourse Meta)

node dist/index.js --site https://meta.discourse.org --profile '~/.config/discourse-mcp/meta.json' --log_level debug
[2026-02-03T14:24:27.536Z] ERROR Failed to load profile: ENOENT: no such file or directory, open '~/.config/discourse-mcp/meta.json'

@nattsw
Copy link
Author

nattsw commented Feb 3, 2026

@xfalcox when we put the value in from a config file e.g. .claude.json it looks like this:

  "mcpServers": {
    "d-sth": {
      "command": "discourse-mcp",
      "args": [
        "--profile",
        "~/.mcps/d-sth.json"
      ]
    },
    ...

So it is currently failing due to this. I can use the absolute path, but when dv is involved, it copies the machine's .claude.json in so it will be the same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants